<template>
	<view class="page index">
		<view class="form">
			<common-input
			  title="项目签约状态" 
				v-model="status"
				:border-bottom="false"
				:disabled="true"
				:require="false"
			>
			</common-input>
			<common-input
			  title="预期签约金额" 
				placeholder="请填写预期签约金额" 
				v-model="money"
				:border-bottom="false"
			>
			</common-input>
			<picker mode="date" @change="selectSignedTime">
				<view class="picker">
					<common-input
					  title="预期签约时间" 
						placeholder="请填写预期签约时间" 
						v-model="signedTime"
						:disabled="true"
					>
					</common-input>
				</view>
			</picker>
			<view class="text">
				<view class="title">
					<view>
						未签约情况说明
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="statusExplain" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<update-file title="未签约情况说明凭证附件" @update="notSignFile"></update-file>
			<picker mode="date" @change="selectStartTime">
				<view class="picker">
					<common-input
					  title="实施开始日期" 
						placeholder="请填写实施开始日期" 
						v-model="startTime"
						:border-bottom="false"
						:disabled="true"
					>
					</common-input>
				</view>
			</picker>
			<picker mode="date" @change="selectEndTime">
				<view class="picker">
					<common-input
					  title="实施终止日期" 
						placeholder="请填写实施终止日期" 
						v-model="endTime"
						:disabled="true"
					>
					</common-input>
				</view>
			</picker>
			<view class="text">
				<view class="title">
					<view>
						实施内容说明
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="content" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<view class="text">
				<view class="title">
					<view>
						实施要求说明
					</view>
					<view class="require"></view>
				</view>
				<textarea v-model="require" placeholder="请输入" placeholder-class="place"></textarea>
			</view>
			<update-file :require="true" :explain="true" title="实施文档" @update="updatefiles"></update-file>
		</view>
		<view class="footer">
			<button @click="save">提交审批</button>
		</view>
	</view>
</template>

<script>
	import commonInput from "@/components/commonInput.vue";
	import updateFile from "@/components/updateFile.vue";
	import {createImplementApi} from "@/api/project_api.js";
	export default{
		data() {
			return{
				status:'未签约',
				money:'',
				signedTime:'',
				statusExplain:'',
				notSignFileUrls: [],
				startTime: '',
				endTime:'',
				content:'',
				require: '',
				projectId: 0,
				fileUrls: []
			}
		},
		components: {
			commonInput,
			updateFile
		},
		onLoad(e) {
			this.projectId = e.id;
		},
		methods:{
			updatefiles(e){
				this.fileUrls = e.map((item) => item.path)
			},
			notSignFile(e){
				this.notSignFileUrls = e.map((item) => item.path)
			},
			// 签约时间
			selectSignedTime(e){
				this.signedTime = e.detail.value
			},
			// 开始时间
			selectStartTime(e){
				this.startTime = e.detail.value
			},
			// 结束时间
			selectEndTime(e){
				this.endTime = e.detail.value
			},
			save(){
				if(this.money == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写预期签约金额'
					})
					return;
				}
				if(this.signedTime == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写预期签约时间'
					})
					return;
				}
				if(this.statusExplain == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写未签约说明'
					})
					return;
				}
				if(this.startTime == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写实施开始时间'
					})
					return;
				}
				if(this.endTime == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写实施终止时间'
					})
					return;
				}
				if(this.content == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写实施内容'
					})
					return;
				}
				if(this.require == ''){
					uni.showToast({
						icon: 'none',
						title: '请填写实施要求'
					})
					return;
				}
				if(this.fileUrls == ''){
					uni.showToast({
						icon: 'none',
						title: '请上传实施文档'
					})
					return;
				}
				uni.showLoading({
					mask: true,
					title: '加载中...'
				})
				createImplementApi({
					projectId: this.projectId,
					expectedSignAmount: this.money,
					expectedSignTime: this.signedTime,
					notSignExplain: this.statusExplain,
					notSignFileUrls: this.notSignFileUrls,
					startDate: this.startTime,
					endDate: this.endTime,
					content: this.content,
					requirement: this.require,
					fileUrls: this.fileUrls
				}).then(() => {
					uni.hideLoading();
					uni.showToast({
						icon: 'success',
						title: '申请成功！'
					})
					setTimeout(() => {
						uni.navigateBack();
					},1500)
				}).catch(() => {
					uni.hideLoading();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/common/style/customicons.scss";
	.index{
		padding: 24rpx 0;
		@include flex-c;
		.form{
			flex: 1 0 0;
			overflow: auto;
			.text{
				border-bottom: 4rpx #e5e5e5 solid;
				padding: 12rpx 30rpx;
				.title{
					font-size: 28rpx;
					color: #101010;
					padding: 0 0 16rpx;
					display: flex;
					align-items: center;
					.require{
					  height: 28rpx;
					  width: 6rpx;
					  background-color: #c24135;
					  margin-left: 10rpx;
				  }
				}
				textarea{
					font-size: 28rpx;
					color: #909090;
					height: 125rpx;
				}
				.place{
					font-size: 28rpx;
					color: #909090;
				}
			}
			&::-webkit-scrollbar{
				display: none;
			}
		}
		.footer{
			flex: 0 0 auto;
			padding: 24rpx 130rpx;
			button{
				@include button;
				background-color: #198AFA;
				color: #fff;
				height: 60rpx;
				line-height: 60rpx;
				font-size: 28rpx;
				width: 100%;
			}
		}
	}
</style>